package com.wxapp.sale.service.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxapp.common.constant.base.IBaseController;
import com.wxapp.common.constant.pojo.vm.ResultVm;
import com.wxapp.common.constant.pojo.vo.UserVo;
import com.wxapp.common.core.annotation.User;
import com.wxapp.sale.api.pojo.vm.goodType.PGoodsTypeDetailVm;
import com.wxapp.sale.api.pojo.vm.goodType.PGoodsTypeListVm;
import com.wxapp.sale.api.pojo.vm.goodType.PGoodsTypeSelectVm;
import com.wxapp.sale.api.pojo.vo.goodType.QGoodsTypeAddVo;
import com.wxapp.sale.api.pojo.vo.goodType.QGoodsTypePageVo;
import com.wxapp.sale.api.pojo.vo.goodType.QGoodsTypeUpdateVo;
import com.wxapp.sale.service.service.GoodsTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author lgl
 * @Description 商品类型
 * @Datetime 2022/6/22 14:25
 * @Modified By
 */
@RestController
@Tag(name = "商品类型")
@RequestMapping("/goods/type")
@RequiredArgsConstructor
public class GoodsTypeController extends IBaseController {
    private final GoodsTypeService goodsTypeService;

    @PostMapping("add")
    @Operation(summary ="添加商品类型")
    public ResultVm<String> add(@Schema(hidden = true) @User UserVo userVo, @RequestBody QGoodsTypeAddVo qGoodsTypeAddVo) {
        return goodsTypeService.add(userVo, qGoodsTypeAddVo);
    }

    @PutMapping("update")
    @Operation(summary ="添加商品类型")
    public ResultVm<String> update(@Schema(hidden = true) @User UserVo userVo, @RequestBody QGoodsTypeUpdateVo qGoodsTypeUpdateVo) {
        return goodsTypeService.update(userVo, qGoodsTypeUpdateVo);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary ="添加商品类型")
    public ResultVm<String> delete(@Schema(hidden = true) @User UserVo userVo, @PathVariable String id) {
        return goodsTypeService.delete(userVo, id);
    }

    @GetMapping("detail")
    @Operation(summary ="获取商品详情")
    public ResultVm<PGoodsTypeDetailVm> detail(@RequestParam String id) {
        return goodsTypeService.detail(id);
    }

    @PostMapping("page")
    @Operation(summary ="获取商品类型")
    public ResultVm<Page<PGoodsTypeListVm>> page(@RequestBody QGoodsTypePageVo QGoodsTypePageVo, @Schema(hidden = true) @User UserVo userVo) {
        return goodsTypeService.page(QGoodsTypePageVo,userVo );
    }

    @GetMapping("select")
    @Operation(summary ="获取商品类型下拉框")
    public ResultVm<List<PGoodsTypeSelectVm>> select(@RequestParam(value = "name", required = false) String name, @Schema(hidden = true) @User UserVo userVo) {
        return goodsTypeService.select(name, userVo);
    }
}
